package com.longdaji.decoration.ui.guide;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.longdaji.decoration.R;
import com.longdaji.decoration.adapter.GuidePagerAdapter;
import com.longdaji.decoration.base.BaseActivity;
import com.longdaji.decoration.ui.login.LoginActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.relex.circleindicator.CircleIndicator;

public class GuideActivity extends BaseActivity implements GuideContract.IView, ViewPager.OnPageChangeListener {
    @Inject
    GuideContract.IPresenter mPresenter;
    @BindView(R.id.tv_start)
    TextView tvStart;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    @BindView(R.id.indicator)
    CircleIndicator indicator;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);

        ButterKnife.bind(this);
        if (mPresenter != null)
            mPresenter.setView(this);
        initView();

    }

    private void initView() {
        viewPager.setAdapter(new GuidePagerAdapter());
        indicator.setViewPager(viewPager);
        viewPager.setCurrentItem(0);
        viewPager.addOnPageChangeListener(this);
        StatusBarUtil.setTranslucentForImageView(this, null);
    }

    @OnClick({R.id.tv_start})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_start:
                startActivity(new Intent(GuideActivity.this, LoginActivity.class));
                finish();
                break;
            default:
                break;
        }
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        if (position == 2) {
            tvStart.setVisibility(View.VISIBLE);
            indicator.setVisibility(View.GONE);
        } else {
            tvStart.setVisibility(View.GONE);
            indicator.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

}
